// pages/bookEnter/classification/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    jl: {
      type: Array
    },
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    goReadBook(e) {
      let id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: `/pages/bookRead/chapter/index?_id=${id._id}&title=${id.title}&cover=${id.cover}&order=${id.order}`,
      })
    },

    removeStorageJl(e) { // 移除历史记录
      // wx.setStorage({
      //   key: 'jl',
      //   data: [],
      // })
      let that = this;
      wx.showModal({
        title: '提示',
        content: '是否删除历史记录',
        confirmText: '确定',
        cancelText: '取消',
        success: function(text) {
          if (text.confirm) {
            let _id = e.currentTarget.dataset.id._id;
            let storageArr = wx.getStorageSync("jl");
            for (let i = 0; i < storageArr.length; i++) {
              if (storageArr[i]._id === _id) {
                storageArr.splice(i, 1)
              }
            }
            wx.setStorage({
              key: 'jl',
              data: storageArr
            })

            that.triggerEvent('tab', that.data.tab)
          } else if (text.cancel) {
            return
          }
        }
      })
    }
  }
})